fix: validate checkout positional reference options - #2233
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No unresolved review issues remain, and all reviewers assessed it as approval-ready.
Pull request overview
Fixes Head.checkout() validation for unsafe positional references, with regression coverage.
Changes:
- Validates positional checkout references.
- Adds tests for local and cloned repositories.
File summaries
| File | Description |
|---|---|
test/test_refs.py |
Adds regression tests for unsafe references. |
git/refs/head.py |
Validates positional checkout references. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Byron
force-pushed
the
clone-check-head-ref
branch
from
September 10, 2026 06:30
d03962f to
0f74a9b
Compare
<!-- agent --> Head.checkout checked keyword options but omitted the serialized reference from its existing unsafe-option validation (GHSA-23mf-xhv8-69c2). Reference names can originate in a cloned repository, so callers could reach behavior that normally requires explicit opt-in without supplying any checkout options themselves. Pass self through the shared option-candidate helper, matching the argument actually sent to Git. This applies the existing policy to direct and cloned references, including abbreviated option spellings, while retaining allow_unsafe_options=True and ordinary checkout semantics. A leading -- separator would instead make the reference a pathspec and break branch switching. Add direct-reference regression coverage and a local clone regression using synthetic file content; the latter also verifies explicit opt-in. Both regression tests failed before the guard change. All 30 tests in test/test_refs.py pass with Python 3.12.14 and Apple Git 2.50.1; git diff --check passes. Git behavior reference: local git/git checkout at 1630431f326e15fcde608827b5ff38422528eb59, builtin/checkout.c checkout_main pathspec_from_file handling, which parses file contents as pathspecs. No Git source was copied. Assisted-by: GPT 6.0 Co-authored-by: GPT 6.0 <codex@openai.com>
Byron
force-pushed
the
clone-check-head-ref
branch
from
September 10, 2026 11:14
0f74a9b to
8da6508
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tasks
This section is for Byron only. Models continuing this PR must not add, remove, check, uncheck, rename, or reorder checkboxes here.
Everything below this line was generated by
Codex GPT-6.Created by Codex on behalf of Byron. Byron will review before this is ready to merge.
Head.checkout()now includes its positional reference in the existing unsafe-option validation. This keeps validation consistent for keyword arguments and reference names, including references obtained from a clone, while preserving explicit opt-in and normal branch switching.Advisory summary
GHSA-23mf-xhv8-69c2: severity high; affected package PyPI GitPython, reported range
<= 3.1.62. No patched version or CVE is assigned in the advisory. The advisory is unpublished; this description omits its reproduction details.Validation
test/test_refs.pypass (Python 3.12.14, Apple Git 2.50.1), including explicit opt-in, ordinary checkout, and detached HEAD behavior.git diff --checkpasses.1630431f326e15fcde608827b5ff38422528eb59,builtin/checkout.cpathspec-file handling. A leading argument separator would change branch checkout into path checkout, so this change reuses the existing validation helper.